<template>
  <el-dialog
    :visible.sync="visible"
    :before-close="beforeClose"
    :close-on-click-modal="false"
    class="dialog-sm"
    title="银行机构"
    top="30px"
  >
    <c-table
      border
      v-loading="loading"
      :stripe="false"
      :columns="tableColumns"
      :data="bankAgencies"
      height="76vh"
    ></c-table>
    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="bankAgencyTotal"
        @current-change="getData"
      ></el-pagination>
      <div></div>
    </div>
  </el-dialog>
</template>
<script>
import { mapGetters } from 'vuex'

export default {
  components: {},
  props: {
    visible: Boolean,
  },
  data() {
    return {
      loading: false,
      params: {
        index: 1,
        size: 50,
        address_code: '',
        'agency_type.eq': 1,
      },
      bankAgencies: [],
      tableColumns: [
        { attrs: { label: '银行名称', prop: 'agency_name', align: 'center' } },
        { attrs: { label: '机构地址', prop: 'address', align: 'center' } },
        { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center' } },
      ],
    }
  },
  computed: {
    ...mapGetters(['user', 'bankAgencyTotal', 'clientId']),
  },
  watch: {},
  created() {
    this.getParams()
    this.getData()
  },
  mounted() {},
  methods: {
    beforeClose() {
      this.$emit('update:visible', false)
    },
    getParams() {
      this.params['service_id.eq'] = this.clientId
    },
    async getData() {
      this.loading = true
      const [res] = await this.$utils.promise(
        this.$api.getData(this.$serviceName, 'credit_agency_access_bank_view', this.params)
      )
      this.loading = false
      const data = (res && res.data) || {}
      this.bankAgencies = data.data || []
      this.$store.commit('bankAgencyTotal', data.totalCount || 0)
    },
  },
}
</script>
<style lang="scss" scoped></style>
